//
//  SCKeyedArchiver.swift
//  SwiftCommon
//
//  Created by lijl on 15/7/27.
//  Copyright (c) 2015年 lijialong. All rights reserved.
//

import Foundation

/// 对象归档
public class SCKeyedArchiver{

    
    /// 把一个对象，比如类转换为NSData
    public class func getNSDataFromObj(obj:AnyObject)->NSData{
    
        return NSKeyedArchiver.archivedDataWithRootObject(obj)
    }
    
    /// 将NSData还原为对象
    public class func getObjFromNSData(data:NSData)->AnyObject?{
    
        return NSKeyedUnarchiver.unarchiveObjectWithData(data)
    }
    
    /// 将一个对象保存到本地文件中
    public class func saveObjToFile(path:String,obj:AnyObject)->Bool{
        
        return NSKeyedArchiver.archiveRootObject(obj, toFile: path)
    }
    
    
    /// 从一个本地文件中读取内容，转换为对象
    public class func getObjFromFile(path:String)->AnyObject?{
    
        return NSKeyedUnarchiver.unarchiveObjectWithFile(path)
    }
    
}